<?php

class LoginController extends Controller
{
	public function actionIndex()
	{
		if(Yii::app()->user->isGuest)
		{
			$this->pageTitle = UserModule::t('Login');

			Yii::app()->menu->set('breadcrumbs', array(
				UserModule::t('Users') => array('/user'),
				$this->pageTitle
			));
			
			$model = new FormUserLogin;
			
			if(isset($_POST['FormUserLogin']))
			{
				$model->attributes = $_POST['FormUserLogin'];
				
				if($model->validate())
				{
					$this->redirect(Yii::app()->getModule('user')->urls['loggedIn']);
				}
			}
			$this->render('index', array('model' => $model));
		}
		else
		{
			$this->redirect(array('home'));
		}
	}
	
}